﻿using System;
using Communication.Message.Util;

namespace Communication.Message.FpgaUpdate
{
	// Token: 0x02000028 RID: 40
	public class SendBlockIndexMessage : FlashUpdateChannelMessage
	{
		// Token: 0x0600014A RID: 330 RVA: 0x00003CDC File Offset: 0x00001EDC
		public SendBlockIndexMessage(byte desId, short blockIndex, int totalRecTimeoutMillis, int spaceRecTimeoutMillis, int sendTimeoutMillis) : base(desId, 4, new byte[]
		{
			(byte)(blockIndex >> 8 & 255),
			(byte)(blockIndex & 255)
		}, 2, 0, totalRecTimeoutMillis, spaceRecTimeoutMillis, sendTimeoutMillis)
		{
			this.blockIndex = blockIndex;
		}

		// Token: 0x0600014B RID: 331 RVA: 0x00003D20 File Offset: 0x00001F20
		public void SetPayload(short blockIndex)
		{
			base.SetPayload(new byte[]
			{
				(byte)(blockIndex >> 8 & 255),
				(byte)(blockIndex & 255)
			}, 0, 2);
			this.blockIndex = blockIndex;
		}

		// Token: 0x0600014C RID: 332 RVA: 0x00003D5C File Offset: 0x00001F5C
		protected override bool DealwithReceiveMsg()
		{
			if (!base.IdentifyFrame())
			{
				return false;
			}
			int num = this.receiveBuffer.ReaderIndex();
			int @ushort = (int)this.receiveBuffer.GetUshort(num + 3);
			short @short = this.receiveBuffer.GetShort(num + 5 + @ushort);
			short num2 = CrcUtil.Crc16(this.receiveBuffer.Array(), this.receiveBuffer.ReaderIndex(), 5 + @ushort, CrcType.High_Low);
			if (@short != num2)
			{
				this.SetFailure(new CrcRrrorException());
				return true;
			}
			if (@ushort == 2 && this.receiveBuffer.GetShort(num + 5) == this.blockIndex)
			{
				this.errorCode = FlashUpdateErrorCode.SUCCESS;
				base.SetSuccess();
				return true;
			}
			this.errorCode = FlashUpdateErrorCode.FAILURE;
			base.SetSuccess();
			return true;
		}

		// Token: 0x0400004C RID: 76
		private short blockIndex;
	}
}
